#include <QDebug>

#include "youkupageparser.h"

namespace Jcr
{
class YoukuPageParserPrivate
{
public:
    QString youkuLink;
};

YoukuPageParser::YoukuPageParser(QObject* parent) : AbstractPageParser(parent)
{
    d_ptr = new YoukuPageParserPrivate;
}

YoukuPageParser::~YoukuPageParser()
{
    delete d_ptr;
}

QString YoukuPageParser::youkuLink() const
{
    return d_ptr->youkuLink;
}

void YoukuPageParser::processNode(GumboNode* node)
{
    if (node->type != GUMBO_NODE_ELEMENT)
        return;

    if (node->v.element.tag == GUMBO_TAG_EMBED) {
        GumboAttribute* attr = gumbo_get_attribute(&node->v.element.attributes, "src");
        if (attr)
            d_ptr->youkuLink = QString(attr->value);
    }
}

void YoukuPageParser::finalize()
{
    emit finished();
}

} // namespace jcr
